package com.ruoyi.web.controller.help;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.help.domain.StudentAfter;
import com.ruoyi.help.service.IStudentAfterService;
import com.ruoyi.help.vo.StudentAfterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学生跟踪Controller
 *
 * @author ruoyi
 * @date 2023-05-20
 */
@RestController
@RequestMapping("/system/after")
public class StudentAfterController extends BaseController {
    @Autowired
    private IStudentAfterService studentAfterService;

    /**
     * 查询学生跟踪列表
     */
    @PreAuthorize("@ss.hasPermi('system:after:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentAfter studentAfter) {
        startPage();
        List<StudentAfter> list = studentAfterService.selectStudentAfterList(studentAfter);
        return getDataTable(list);
    }

    /**
     * 导出学生跟踪列表
     */
    @PreAuthorize("@ss.hasPermi('system:after:export')")
    @Log(title = "学生跟踪", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentAfter studentAfter) {
        List<StudentAfter> list = studentAfterService.selectStudentAfterList(studentAfter);
        ExcelUtil<StudentAfter> util = new ExcelUtil<StudentAfter>(StudentAfter.class);
        util.exportExcel(response, list, "学生跟踪数据");
    }

    /**
     * 获取学生跟踪详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:after:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(studentAfterService.selectStudentAfterById(id));
    }

    /**
     * 新增学生跟踪
     */
    @PreAuthorize("@ss.hasPermi('system:after:add')")
    @Log(title = "学生跟踪", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentAfterVo studentAfterVo) {
        int i = studentAfterService.insertStudentAfter(studentAfterVo);
        if (i == -5) {
            return AjaxResult.error("关键信息不能为空");
        }

        return toAjax(studentAfterService.insertStudentAfter(studentAfterVo));
    }

    /**
     * 修改学生跟踪
     */
    @PreAuthorize("@ss.hasPermi('system:after:edit')")
    @Log(title = "学生跟踪", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentAfter studentAfter) {
        return toAjax(studentAfterService.updateStudentAfter(studentAfter));
    }

    /**
     * 删除学生跟踪
     */
    @PreAuthorize("@ss.hasPermi('system:after:remove')")
    @Log(title = "学生跟踪", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(studentAfterService.deleteStudentAfterByIds(ids));
    }
}
